<template>
    <div class="menu-table">
      <div class="table-con">
        <div class="con">
          <div class="back pl10 pr10">
            <span @click="backBtn">
              <img
                src="@/assets/imgs/biaozhi.png"
                width="24px"
                height="24px"
                alt="biaozhi"
              />
              Transit forecast
            </span>
            <i
              class="iconfont icon-fanhui f16 curPointer"
              @click="handleBackHome"
            ></i>
          </div>
          <div class="menu-item-con mt15">
            <div class="collapse-container">
              <!-- 每层item -->
              <div
                v-for="({ label, id,tableData ,coverageRate,productId}, index) in collapseBtnList"
                :key="index"
                class="pl5 pr5"
              >
                <div class="title-con" @click="setChooseCollapse(id,tableData,productId,collapseBtnList[index])">
                  <div class="left-title">
                    <img src="@/assets/imgs/file.png" alt="file" width="18px" height="16px">
                    <span class="pl5 pr5">{{ label }}</span>
                  </div>
                  <div class="right-title">
                    <div class="rate mr5">
                      Coverage <span :class="coverageRate=='100.00'?'yellowFont':'redFont'">{{ coverageRate }}%</span>
                    </div>
                    <span title="Export transit area" class="iconfont icon-fenxi mr5 ml10 "
                          style="font-size: 22px;cursor: pointer" @click.stop="handleExport(tableData)"></span>
                    <span
                      class="curPointer mr10 el-collapse-item__arrow el-icon-arrow-right"
                      :class="id === choose ? 'is-active' : ''"
                    ></span>
                  </div>
                </div>
                <!-- 内容 -->
                <div
                  :class="
                    id === choose
                      ? 'content-show content-animation'
                      : 'content-hidden content-animation'
                  "
                  style="overflow: hidden"
                  class="collapse-content common-table-container pt15"
                >
                  <div class="tips pl5" v-show="id === choose">
                    <img src="@/assets/imgs/tips.png" width="20" height="20" style="vertical-align: middle">   <span>Click record to view the trajectory simulation</span>
                  </div>
                  <el-table
                    aria-setsize="mini"
                    class="customer-no-border-table"
                    :data="tableData"
                    height="300px"
                    style="width: 100%"
                    @row-click="handleCurrentChange"
                    @selection-change="handleSelectionChange"
                    highlight-current-row
                    header-align="center"
                    align="center"
                  >
                    <el-table-column align="center" label="" type="selection" width="55">
                    </el-table-column>
                    <el-table-column label="Num" width="70" type="index">
                    </el-table-column>
                    <el-table-column width="120" prop="satelliteCode" label="Satellite">
                    </el-table-column>
                    <el-table-column width="180" prop="startTime" label="entryTime"
                                     :formatter="gridDateFormatter"
                    >
                    </el-table-column>
                    <el-table-column width="180" prop="endTime" label="exitTime"
                                     :formatter="gridDateFormatter">
                    </el-table-column>
                    <el-table-column prop="clothWidth" width="120" label="clothWidth">
                    </el-table-column>
                    <!--                    <el-table-column label="operate" width="150px">-->
                    <!--                      <template slot-scope="scope">-->

                    <!--                           <el-button-->
                    <!--                             class="opeBtn"-->
                    <!--                             size="mini"-->
                    <!--                             @click.stop="handleEdit( scope.row)">Flight Simulator</el-button>-->
                    <!--                      </template>-->
                    <!--                    </el-table-column>-->
                  </el-table>
                </div>
              </div>
            </div>
          </div>
          <div class="bottom-btn" @click="handleReport">Generate <br /> Tranait Report</div>
        </div>
      </div>
      <div class="left-arrow-contract" @click="queryVisible=!queryVisible" ></div>
    </div>
</template>

<script>
import { getTimeYMDMS } from "@/utils/public";
import { windowOpen } from "@/utils/utils";

export default {
  props: ["collapseBtnList"],
  data() {
    return {
      isShowStatic: false,
      queryVisible: true,
      activeNames: "",
      choose: 0,
      staticVisible: false,
      multipleSelection: [],
      LeftWidth: 460,
    };
  },
  mounted() {
    if (this.collapseBtnList.length > 0) {
      const firstData = this.collapseBtnList[0];
      this.setChooseCollapse(firstData.id,firstData.tableData,firstData.productId, firstData)
    }
  },
  methods: {
    /**
     * 卫星扫描动画方法
     * */
    handleEdit(val) {
      this.$emit("handleEdit", val);
    },
    backBtn() {
      this.isShowStatic = !this.isShowStatic;
      this.$emit("handleStatic", this.isShowStatic);
    },
    handleBackHome() {
      this.$emit("handleBackHome");
    },
    gridDateFormatter(row, column, cellValue) {
      if (cellValue == null || cellValue == "") return "";
      let data = row[column.property];
      return getTimeYMDMS(data);
    },
    toggleMenu() {
      this.queryVisible = !this.queryVisible;
    },
    setChooseCollapse(index, tableData, productId, item) {
      let LegendData = [];
      if (this.choose === index) {
        this.choose = "";
        LegendData = [];
      } else {
        this.choose = index;
        LegendData = tableData;

      }
      this.staticVisible = true;
      this.$emit("showRightLegend", LegendData, productId, item);
    },

    /**导出
     * */
    async handleExport(tableData) {

      if (this.multipleSelection.length === 0) {
        this.multipleSelection = tableData;
      }
      const params = this.multipleSelection.map(item => {
        return {
          clothWidth: item.clothWidth,
          endTime: item.endTime,
          satelliteName: item.satelliteCode,
          startTime: item.startTime,
          theGeom: JSON.stringify(item.stripGeoJson)
        };
      });

      const url = `/baseServer/rsmis-gdyc-service/orbital_prediction_calc/satelliteTrajectoryDownload`;
      // const res= await downloadSatelliteTrajectory(params)
      // console.log(res);
      windowOpen(url, "data_list.zip", params, "", "POST");

      // let result = response.result;
      // const localUrl = `https://${localIP}/satTle/exportRouteZip?zipName=${result}`;
      // window.location.href = localUrl;
      // const allData = JSON.parse(localStorage.getItem("collapseData")) || [];
      // const matchedItem = allData.find(item => item.id ===id);
      // if (Object.keys(matchedItem).length === 0) {
      //   return;
      // }

    },
    handleReport() {
      this.$message.warning("This feature is under development");
    },
    showStatic(item) {
      this.staticVisible = true;
      this.$emit("showStatic", this.staticVisible, item);
    },
    handleCurrentChange(val) {
      this.$emit("handleCurrentChange", val);
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>

<style scoped lang="scss">
.container-result {
  width: 460px;
  height: 670px;
  background: #1f222a;
  box-shadow: 2px 0px 4px 0px rgba(5, 11, 30, 0.4);
  position: absolute;
  top: 0px;
  left: 0px;
  z-index: 200;
  transition: all .3s ease-out;
}

.table-con {
  width: 100%;
  height: 100%;
  position: relative;

  .con {
    width: 100%;
    height: 100%;
    position: relative;

    .back {
      width: 100%;
      height: 60px;
      background: #071019;
      display: flex;
      justify-content: space-between;
      align-items: center;
      color: #fff;
      font-size: 20px;
      box-sizing: border-box;
    }
  }

  :deep(.el-collapse) {
    border: none;
  }

  :deep(.el-collapse-item) {
    width: 96%;
    height: 50px;
    background: url("~@/assets/imgs/title-bg.png") no-repeat;
    background-size: 100%;
    padding: 0 10px;
    box-sizing: border-box;
    margin: 10px auto;

    &:last-child {
      margin-bottom: 0;
    }

    :deep( .el-collapse-item__header,
    .el-collapse-item__wrap ) {
      font-size: 16px;
      color: #fff;
      border-radius: 4px;
      background-color: transparent;
    }

    .el-collapse-item__header {
      height: auto;
      border: none;
    }

    .el-collapse-item__wrap {
      margin-top: 10px;
      border-bottom: none;
    }

    .el-collapse-item__content {
      position: relative;
    }
  }

  .collapse-content {
    color: #fff;
  }
}

.conManage {
  width: 137px;
  height: 59px;
  display: flex;
  justify-content: center;
  align-items: center;
  background: url("~@/assets/imgs/configurabtn.png") no-repeat;
  background-size: 100%;
  color: #fff;
  font-size: 14px;
  cursor: pointer;
}

// 表格部分样式
// 最外层透明
::v-deep .el-table,
::v-deep .el-table__expanded-cell {
  background-color: transparent;
  color: #fff;
  font-size: 24px;
  border-right: 1px solid #474d55;
}

// 表格内背景颜色
::v-deep .el-table th,
::v-deep .el-table tr,
::v-deep .el-table td {
  background-color: transparent;
  color: #fff;
  font-size: 14px;
  border: none;
  height: 5px;
  font-weight: Normal;
}

// 去掉最下面的那一条线
.el-table::before {
  height: 0px;
}

// 设置表格行高度
::v-deep .el-table__body tr,
::v-deep .el-table__body td {
  height: 30px;
  //border-bottom: 1px solid #474d55;
}

:deep(.el-table--enable-row-transition .el-table__body tr:last-child,.el-table__body tr:last-child td) {
  border-bottom: none !important;
}

// 修改高亮当前行颜色
::v-deep .el-table tbody tr:hover > td {
  background: #474D55 !important;
}

// 修改表头样式-加边框
::v-deep .el-table__header-wrapper {
  //border: 1px solid #474d55;
}

// 表格斑马自定义颜色
::v-deep .el-table__row.warning-row {
  background: #474D55 !important;
}

// 滚动条样式
::v-deep .el-table__body-wrapper::-webkit-scrollbar-track {
  background-color: rgba(120, 120, 120, 1);
}

::v-deep .el-table__body-wrapper::-webkit-scrollbar {
  width: 10px;
  opacity: 0.5;
}

::v-deep .el-table__body-wrapper::-webkit-scrollbar-thumb {
  border-radius: 15px;
  background-color: rgba(198, 198, 198, 1);
}

.el-table thead {
  background: #2c2d32;
}
.el-table__body tr.current-row>td{
  background: #474D55 !important;
}

::v-deep .el-table__body-wrapper {
  border-right: 1px solid #474d55;
  border-left: 1px solid #474d55;
}

.title-con {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 96%;
  height: 50px;
  background: url("~@/assets/imgs/title-bg.png") no-repeat;
  background-size: 100%;
  padding: 0 10px;
  box-sizing: border-box;
  margin: 10px auto;
  color: #fff;

  .right-title {
    display: flex;
    justify-content: center;
    align-items: center;

    .rate {
      width: 70px;
      line-height: 20px;
      height: 42px;
      background: url("~@/assets/imgs/rate-bg.png") no-repeat;
      background-size: 100%;
      border-radius: 4px;
      font-size: 12px;
      text-align: center;
      color: #fff;

      .redFont {
        color: #ff7676;
      }

      .yellowFont {
        color: #eccf7e;
      }
    }
  }
}

.bottom-btn {
  width: 120px;
  padding: 5px;
  background: #4E9EFF;
  border-radius: 4px;
  font-size: 14px;
  font-weight: 400;
  color: #ffffff;
  box-sizing: border-box;
  text-align: center;
  position: absolute;
  bottom: 10px;
  left: 50%;
  margin-left: -80px;
  cursor: pointer;
}


// collapse内容显示
.content-show {

  height: 350px;
}

// collapse内容隐藏
.content-hidden {
  height: 0px;
}

.el-collapse-item__arrow {
  margin: 0 !important;
  flex: auto;

}

// 添加内容高度变化时动画
.content-animation {
  transition: height 0.15s cubic-bezier(0, 0.1, 0.15, 1) 0.15s;
  -moz-transition: height 0.15s cubic-bezier(0, 0.1, 0.15, 1) 0.15s; /* Firefox 4 */
  -webkit-transition: height 0.15s cubic-bezier(0, 0.1, 0.15, 1) 0.15s; /* Safari 和 Chrome */
  -o-transition: height 0.15s cubic-bezier(0, 0.1, 0.15, 1) 0.15s; /* Opera */
}

// 三角旋转
.triangle-route {
  transform: rotate(90deg);
  -ms-transform: rotate(90deg); /* IE 9 */
  -webkit-transform: rotate(90deg); /* Safari and Chrome */
  color: #222222;
  transition: transform .3s
}

// 文本默认
.title {
  font-size: 16px;
  font-weight: bold;
}

// 点击collapse时的文本变化
.span-click {
  color: #212121;
}

// 点击其他collapse时的文本变化
.span-lose {
  color: #888888;
}

.common-table-container {
  overflow: hidden;
  width: 98%;
  margin: 0 auto;
}

.el-table td.el-table__cell, .el-table th.el-table__cell.is-leaf {
  border-bottom: none;
}

:deep( .el-table th.el-table__cell.is-leaf) {
  border-bottom: none;
}

.el-table__body tr.current-row > td {
  background: #474D55 !important;// 设置高亮的背景颜色

}

::v-deep .el-table__body tr.current-row > td.el-table__cell, ::v-deep .el-table__body tr.selection-row > td.el-table__cell {
  background: #474D55 !important; // 设置高亮的背景颜色
}

::v-deep(tr.el-table__row:last-child, .el-table__body tr:last-child,.el-table__body tr:last-child td) {
  border-bottom: none;
}

::v-deep .el-table__empty-block {
  min-height: 60px;
  text-align: left;
  width: 100%;
  display: flex;
  /* justify-content: center; */
  align-items: center;
}

.left-arrow-contract {
  position: absolute;
  top: 35%;
  transform: translateY(-50%);
  height: 60px;
  width: 16px;
  right: -16px;
  z-index: 200;
  background-image: url('@/assets/imgs/left_arrow2.png');
  background-size: 100% 100%;
  cursor: pointer;
}
.tips{
  margin-top: -10px;
  color: #ffd675;
  vertical-align: middle;
  font-size: 12px;
}
.menu-table{
  height: 550px;
  width: 100%;
}
</style>
